﻿using UnityEngine;
using System;
using System.Collections.Generic;
using System.Collections;


public class WorldSceneManager : LTEventListenerC {
	public static int newOpenAreaId = 0;
	public static bool isSentSearch = false;
	public static bool isSuccessSearch = false;
	public static int sentResearchAreaId = 0;
	public static bool isRegionLevelUp = false;

	public GameObject worldMapObject;
	public GameObject areaViewObject;
	public GameObject dispatchInfoViewObject;

	public UILabel[] areaLevelInWorldMap;
	public UILabel[] areaDispatchMemberCountInWorldMap;
	public UILabel[] areaDispatchRemainTimeInWorldMap;
	public GameObject[] areaDispatchIngMarkObject;
	public GameObject[] areaNoDispatchMarkObject;
	public GameObject[] areaNotOpenTextObject;
    public GameObject[] betweenAreaRoadObjectInWorldMap;

	public UISprite[] areaIconImage;
	public UILabel[] areaNameLabel;
	public UILabel areaLevelLabel;
	public UILabel areaExpLabel;
	public UILabel areaOpenCountLabel;
	public UILabel areaMemberCurrCountLabel;
	public UILabel areaMemberMaxCountLabel;
	public UILabel areaRemainTimeLabel;
	public GameObject[] areaBonusSpecObject;
	public UISlider areaExpBar;

	public UISprite[] notOpenAreaImage;

	GameObject[] tipObject;
	UILabel[] tipBodyLabel;

	public GameObject[] areaIngIconList;
	public GameObject[] areaDisPatchIconList;

	public GameObject newAreaIcon;

	public GameObject wolrdMapBackground;
	public GameObject[] wolrdMapBackground2;
	public GameObject[] areaBackground;

	public GameObject[] areaPointObjectList;

	public GameObject researchButton;
	public GameObject dispatchButton;

	public GameObject dispatchNormalButton;
	public GameObject dispatchIngButton;
	public GameObject dispatchEndButton;

	public GameObject selectDispatchMemberListObject;

	public GameObject[] dispatchDetailState;
	public UILabel[] dispatchMemberCountInDetail;
	public UILabel[] dispatchMemberMaxCountInDetail;
	public UILabel[] dispatchTimeInDetail;
	public GameObject[] dispatchButtonsInDetail;

	public GameObject expansionWarButton;

    public Camera BGCamera;
    public Camera UICamera;

	const int RareMax = 6;
	const float StarCenter = 10.0f;
	const float StarGap = 26.0f;

	public override void AwakeScene ()
	{
		base.AwakeScene ();

		hasLeftTopMenu = true;
		hasBackButton = true;
		//SetActiveHelpButton(true);

		WorldExtensionBattleStageScene.isExpansionWar = false;

		//BGM 재생 임시 적용
		if( UserData.Instance.userModel.regions.regionMap_Dic.Count == 1 )
			BGM = "BGM_Map_Poeta";
        else if (UserData.Instance.userModel.regions.regionMap_Dic.Count == 2)
			BGM = "BGM_Map_Berteron";
        else if (UserData.Instance.userModel.regions.regionMap_Dic.Count == 3)
            BGM = "BGM_Map_Teobomos";
        else if (UserData.Instance.userModel.regions.regionMap_Dic.Count == 4)
            BGM = "BGM_Map_Eltenen";
	}

	// Use this for initialization
	public override void StartScene () {
        SetActiveHelpButton(false);
		if( UserData.Instance.userModel == null )
		{
			ResourceManager.Inst.PatchDataFile( ()=> {
				GameData.Init();
				CashData.Init();
				//			TextData.Init();
				EventData.Init();
			});

			NetworkManager.Instance.C2S_LOGIN(AuthPlatformID.None, "shinpc00", string.Empty, ResponseLogin, null);
		}
		else
		{
			SetWorldMapInfos();
		}

		if( newOpenAreaId != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiPopupExpansionCaution1"), string.Format("{0}\n\n{1}", TextController.GetStringWithId("uiPopupExpansionCaution2").Replace("{0}", TextController.GetStringWithId(string.Format("region{0}", newOpenAreaId.ToString()))), TextController.GetStringWithId("uiPopupExpansionCaution3")));
			newOpenAreaId = 0;
		}

		if( isRegionLevelUp )
		{
			Popup_AreaLevelUpReward popup = PopupManager.PushPopup(PopupKind.AreaLevelUpReward) as Popup_AreaLevelUpReward;
			popup.SetKinaAmount();
			isRegionLevelUp = false;
		}

		if( (isSentSearch && UserData.Instance.researchResultData != null) )
		{
			GotoAreaView(UserData.Instance.researchResultData.regionId-100);
		}

		if( StandbyScene.startMode == BattleStartMode.Research )
		{
			GotoAreaView(selectedAreaIndex);
			StandbyScene.startMode = BattleStartMode.None;
		}
        
        if( UserData.Instance.userModel.level < GameData.Inst.GetConstantData("OPEN_LEVEL_EXTENSION").value )
        {
            GotoAreaView(0);
        }

//		if(isSentSearch)
//		{
//			worldMapObject.SetActive(false);
//			worldMapObject.SetActive(false);
//			areaViewObject.GetComponent<AreaView>().SetAreaViewInfos(selectedMainAreaIndex, selectedAreaIndex);
//			areaViewObject.SetActive(true);
//		}
	}

	private void ResponseLogin(ResponseModel<UserModel> result)
	{
		if (result.ecode != 0)
			return;

		UserData.Instance.userModel = result.data;

		SetWorldMapInfos();
	}

    public override void BackButton()
    {
        base.BackButton();

		if( worldMapObject.activeSelf || (UserData.Instance.userModel.level < GameData.Inst.GetConstantData("OPEN_LEVEL_EXTENSION").value) )
        	SceneController.LoadLevel("Main");
		else
		{
			worldMapObject.SetActive(true);
			wolrdMapBackground.SetActive(true);
			HideResourceAreaTipWindow();
			areaViewObject.SetActive(false);
			foreach(GameObject obj in areaBackground)
				obj.SetActive(false);
			dispatchInfoViewObject.SetActive(false);
            Popup_Blur.ClearAll();
            var blur_effect = Popup_Blur.GetActivated(UICamera);
            if( blur_effect != null )
            {
                Popup_Blur.RemoveBackground(blur_effect, BGCamera);
                Popup_Blur.Deactivate(UICamera);
            }
		}
    }
	
	// Update is called once per frame
	void Update () {
		if(UserData.Instance.userModel != null )
			CheckAndShowDispatchRemainTime();
	}

	int selectedMemberIndex = -1;
	public override void OnEvent (int eventID)
	{
		base.OnEvent (eventID);

		if( eventID < 100 )
		{
			GotoAreaView(eventID);
		}
		else if( eventID >= 100 && eventID < 200 )
		{
//			if( eventID - 100 < UserData.Instance.userModel.regions.regionMap[selectedAreaId].spotOpen + 1 )
				ShowResourceAreaTipWindow(eventID - 100);
		}

		if( eventID > 1000 )
		{
			SelectDispatchMember(eventID-1000);
			selectedMemberIndex = eventID;
		}
	}

	void ShowResourceAreaTipWindow(int index)
	{
		LTButtonMessage[] temp = areaPointObjectList[selectedAreaIndex].GetComponentsInChildren<LTButtonMessage>();
		foreach(LTButtonMessage t in temp)
			t.transform.FindChild("Tip").gameObject.SetActive(false);

		Transform areaObject = areaPointObjectList[selectedAreaIndex].transform.FindChild("area_0"+index);
		if( areaObject == null )
			areaObject = areaPointObjectList[selectedAreaIndex].transform.FindChild("area_"+index);
		areaObject.FindChild("Tip").gameObject.SetActive(true);
		int resourceBonusType = 0;
		foreach(DRegionSpot spotInfo in GameData.Inst.regionSpot)
		{
			if( spotInfo.regionID == int.Parse(selectedAreaId) )
			{
				if(spotInfo.spotID == index )
				{
					string text = TextController.GetStringWithId(string.Format("uiRegionSpotInfo{0}", spotInfo.bonusType));
					if( !text.Contains("{1}") )
					{
						text = text.Replace("{0}", spotInfo.value1.ToString());
					}
					else
					{
						if( spotInfo.bonusType == 5 || spotInfo.bonusType == 6 )
						{
							foreach(DItem itemInfo in GameData.Inst.item)
							{
								if( itemInfo.itemID == spotInfo.value1 )
								{
									text = text.Replace("{0}", TextController.GetItemName(itemInfo)).Replace("{1}", spotInfo.value2.ToString());
									break;
								}
							}
						}
						else
						{
							text = text.Replace("{0}", spotInfo.value1.ToString()).Replace("{1}", spotInfo.value2.ToString());
						}
					}

					if( index > UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen )
						text = string.Format("[6c6c6c]{0}[-]", text);

					areaObject.FindChild("Tip").FindChild("body").GetComponent<UILabel>().text = text;
				}
			}
		}
	}

	public void HideResourceAreaTipWindow()
	{
		LTButtonMessage[] temp = areaPointObjectList[selectedAreaIndex].GetComponentsInChildren<LTButtonMessage>();
		Debug.LogError(temp.Length);
		foreach(LTButtonMessage t in temp)
			t.transform.FindChild("Tip").gameObject.SetActive(false);
	}

	public static int GetSelectedAreaId()
	{
		if(selectedAreaId=="")
		{
			Debug.LogError(" selectedAreaId empty temp 100");
			return 100;//테스트 배틀을 위해 일단 임시로.//
		}
		return int.Parse(selectedAreaId);
	}

	static int selectedAreaIndex = 0;
	static string selectedAreaId = "";
	public void GotoAreaView(int index)
	{
		selectedAreaIndex = index;
		selectedAreaId = (100+index).ToString();
		if( UserData.Instance.userModel.regions.regionMap_Dic.ContainsKey((100+index).ToString()) )
		{
			worldMapObject.SetActive(false);
			wolrdMapBackground.SetActive(false);
	//		areaViewObject.GetComponent<AreaView>().SetAreaViewInfos(selectedMainAreaIndex, selectedAreaIndex);
			SetAreaInfo(index);
			areaBackground[index].SetActive(true);
			areaViewObject.SetActive(true);
			areaPointObjectList[index].SetActive(true);
		}
		else
		{
			//Go To Expansion Battle!
			WorldExtensionBattleStageScene.selectedAreaId = int.Parse(selectedAreaId);
			WorldExtensionBattleStageScene.selectedAreaIndex = selectedAreaIndex;
			SceneController.LoadLevel("Expansion");
		}
	}

	void SetWorldMapInfos()
	{
		foreach(KeyValuePair<string, Region> pair in UserData.Instance.userModel.regions.regionMap_Dic)
		{
			areaLevelInWorldMap[pair.Value.id-100].text = string.Format("{0}(Lv {1})", TextController.GetStringWithId(string.Format("region{0}", pair.Value.id)), UserData.Instance.userModel.regions.regionMap_Dic[pair.Value.id.ToString()].regionLevel.ToString());
			areaLevelInWorldMap[pair.Value.id-100].color = Color.white;
			areaDispatchIngMarkObject[pair.Value.id-100].SetActive(false);
			areaNoDispatchMarkObject[pair.Value.id-100].SetActive(true);
//			areaNotOpenTextObject[pair.Value.id-100].SetActive(false);
			areaNoDispatchMarkObject[pair.Value.id-100].transform.parent.gameObject.GetComponent<LTButtonMessage>().enabled = true;
			if( areaNoDispatchMarkObject[pair.Value.id-100].transform.FindChild("world_icon_open") != null )
				areaNoDispatchMarkObject[pair.Value.id-100].transform.FindChild("world_icon_open").gameObject.SetActive(true);
		}

		if( UserData.Instance.userModel.regions.regionMap_Dic.Count < 4 )
		{
			expansionWarButton.transform.parent = areaNoDispatchMarkObject[UserData.Instance.userModel.regions.regionMap_Dic.Count].transform.parent;
			expansionWarButton.transform.localPosition = new Vector3(0f, 45f, 0f);
			expansionWarButton.transform.localScale = Vector3.one;
			expansionWarButton.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventId = UserData.Instance.userModel.regions.regionMap_Dic.Count;
		}
		else
		{
			expansionWarButton.SetActive(false);
		}

		Debug.LogError(UserData.Instance.userModel.regions.expansionWarId);
		Debug.LogError(UserData.Instance.userModel.regions.expansionWarStep);
		Debug.LogError(UserData.Instance.userModel.regions.regionIds.Length);
		Debug.LogError("UserData.Instance.userModel.regions.regionMap.Count -- " + UserData.Instance.userModel.regions.regionList.Count);
		Debug.LogError("UserData.Instance.userModel.regions.regionMap_Dic.Count -- " + UserData.Instance.userModel.regions.regionMap_Dic.Count);
		areaLevelInWorldMap[UserData.Instance.userModel.regions.regionMap_Dic.Count].color = new Color(255/255f, 112/255f, 112/255f);
        wolrdMapBackground2[UserData.Instance.userModel.regions.regionMap_Dic.Count-1].SetActive(true);
	}

	void SetAreaInfo()
	{
		SetAreaInfo(selectedAreaIndex);
	}

	void SetAreaInfo(int areaIndex)
	{
		foreach(GameObject obj in areaBonusSpecObject)
		{
			obj.SetActive(false);
		}

		foreach(GameObject obj in areaPointObjectList)
		{
			obj.SetActive(false);
		}

		//지역 정보 설정
		areaNameLabel[0].text = TextController.GetStringWithId(string.Format("AreaTitleRegion{0}", selectedAreaId));
		areaNameLabel[1].text = string.Format("{0} [969696]({1}/{2})[-]", TextController.GetStringWithId(string.Format("region{0}", selectedAreaId)), UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen, GameData.Inst.GetMaxResourceSpotCount(int.Parse(selectedAreaId)).ToString());
		areaLevelLabel.text = string.Format("Lv {0}", UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel);
		areaExpBar.value = (float)UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionExp/GameData.Inst.regionLevel[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].regionExp;
		areaExpLabel.text = string.Format("{0}%", (int)(areaExpBar.value*100));
		areaMemberMaxCountLabel.text = string.Format("{0}", TextController.GetStringWithId("uiCommonTextMaxCount").Replace("{0}", GameData.Inst.regionLevel[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].dispatchNum.ToString()));
		areaMemberCurrCountLabel.text = string.Format("{0}", TextController.GetStringWithId("uiCommonTextpeople").Replace("{0}", UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList.Length.ToString()));

		areaPointObjectList[areaIndex].SetActive(true);

//		자원지 오픈 상태 여부 표시
		for(int i=0; i<UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen; i++)
		{
			Debug.LogError("area_"+(i+1));
			Transform areaObject = areaPointObjectList[areaIndex].transform.FindChild("area_0"+(i+1));
			if( areaObject == null )
				areaObject = areaPointObjectList[areaIndex].transform.FindChild("area_"+(i+1));
			if( areaObject != null )
			{
				areaObject.FindChild("01").gameObject.SetActive(false);
				areaObject.FindChild("02").gameObject.SetActive(true);
				areaObject.FindChild("02").FindChild("new").gameObject.SetActive(false);
			}
		}

		Region regionInfo = UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId];
		Debug.LogError(Constants.ConvertFromUnixTimestamp(regionInfo.endDispatch));
		Debug.LogError(DateTime.Now);
		TimeSpan remainTime = Constants.ConvertFromUnixTimestamp(regionInfo.endDispatch) - (DateTime.Now - UserData.Instance.serverTimeOffsetSpan);
		Debug.LogError(remainTime.TotalSeconds);
		if( regionInfo.dispatchMList.Length > 0 && remainTime.TotalSeconds > 0 )
		{
			dispatchNormalButton.SetActive(false);
			dispatchIngButton.SetActive(true);
			dispatchEndButton.SetActive(false);
		}
		else if( regionInfo.dispatchMList.Length > 0 && remainTime.TotalSeconds == 0 )
		{
			dispatchNormalButton.SetActive(false);
			dispatchIngButton.SetActive(false);
			dispatchEndButton.SetActive(true);
		}
		else
		{
			dispatchNormalButton.SetActive(true);
			dispatchIngButton.SetActive(false);
			dispatchEndButton.SetActive(false);
		}

		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
//		icon_exp@sprite
		if( areaBonusSpecObject[0].transform.FindChild("body") != null )
		{
			areaBonusSpecObject[0].transform.FindChild("body").GetComponent<UILabel>().text = TextData.Get("uiWorldInfoKina").Replace("{0}", GameData.Inst.regionLevel[regionInfo.regionLevel-1].kina.ToString());
			areaBonusSpecObject[0].SetActive(true);
		}
		if( areaBonusSpecObject[0].transform.FindChild("icon") != null )
		{
			areaBonusSpecObject[0].transform.FindChild("icon").GetComponent<UISprite>().spriteName = "icon_quina@sprite";
			areaBonusSpecObject[0].SetActive(true);
		}
		if( areaBonusSpecObject[1].transform.FindChild("body") != null )
		{
			areaBonusSpecObject[1].transform.FindChild("body").GetComponent<UILabel>().text = TextData.Get("uiWorldInfoChar").Replace("{0}", GameData.Inst.regionLevel[regionInfo.regionLevel-1].charExp.ToString());
			areaBonusSpecObject[1].SetActive(true);
		}
		if( areaBonusSpecObject[1].transform.FindChild("icon") != null )
		{
			areaBonusSpecObject[1].transform.FindChild("icon").GetComponent<UISprite>().spriteName = "icon_exp@sprite";
			areaBonusSpecObject[1].SetActive(true);
		}
//		if( areaBonusSpecObject[2].transform.FindChild("body") != null )
//		{
//			areaBonusSpecObject[2].transform.FindChild("body").GetComponent<UILabel>().text = TextData.Get("uiWorldInfoLegion").Replace("{0}", GameData.Inst.regionLevel[regionInfo.regionLevel-1].legionExp.ToString());
//			areaBonusSpecObject[2].SetActive(true);
//		}
//		if( areaBonusSpecObject[2].transform.FindChild("icon") != null )
//		{
//			areaBonusSpecObject[2].transform.FindChild("icon").GetComponent<UISprite>().spriteName = "icon_exp@sprite";
//			areaBonusSpecObject[2].SetActive(true);
//		}

		int k=2;

		foreach(DRegionCharTrait charTraitInfo in GameData.Inst.regionCharTrait)
		{
			if( charTraitInfo.regionID == int.Parse(selectedAreaId) )
			{
				foreach(DTrait traitInfo in GameData.Inst.trait)
				{
					if( traitInfo.id == charTraitInfo.traitID )
					{
						if( charTraitInfo.weight >= traitInfo.weight )
						{
							if( areaBonusSpecObject[k].transform.FindChild("body") != null )
							{
								areaBonusSpecObject[k].transform.FindChild("body").GetComponent<UILabel>().text = TextData.Get("uiWorldInfoTrait").Replace("{0}", TextData.Get("trait"+traitInfo.id));
								if( areaBonusSpecObject[k].transform.FindChild("icon") != null )
								{
									areaBonusSpecObject[k].transform.FindChild("icon").GetComponent<UISprite>().spriteName = "icon_member@sprite";
								}
								areaBonusSpecObject[k++].SetActive(true);
								continue;
							}
						}
					}
				}
			}
		}

		foreach(DDispatchReward rewardInfo in GameData.Inst.dispatchReward)
		{
			if( rewardInfo.regionID == int.Parse(selectedAreaId) )
			{
				if( rewardInfo.type == 2 )
				{
					if( areaBonusSpecObject[k].transform.FindChild("body") != null )
					{
						areaBonusSpecObject[k].transform.FindChild("body").GetComponent<UILabel>().text = TextController.GetItemName(rewardInfo.value1);
						if( areaBonusSpecObject[k].transform.FindChild("icon") != null )
						{
							areaBonusSpecObject[k].transform.FindChild("icon").GetComponent<UISprite>().spriteName = "icon_item@sprite";
						}
						areaBonusSpecObject[k++].SetActive(true);
						continue;
					}
				}
			}
		}


		if( int.Parse(selectedAreaId) == sentResearchAreaId && isSuccessSearch && isSentSearch )
		{
			if( UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen < GameData.Inst.GetMaxResourceSpotCount(int.Parse(selectedAreaId)) )
			{
				Transform areaObject = areaPointObjectList[selectedAreaIndex].transform.FindChild("area_0"+UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen);
				if( areaObject != null )
				{
					areaObject.FindChild("01").gameObject.SetActive(false);
					areaObject.FindChild("02").gameObject.SetActive(true);
					areaObject.FindChild("02").FindChild("new").gameObject.SetActive(true);
				}
			}
		}
		isSentSearch = isSuccessSearch = false;
		sentResearchAreaId = 0;
		UserData.Instance.researchResultData = null;
	}
	 
	List<MemberListCell> memberCellList = new List<MemberListCell>();
	void SetDispathInfoViewInfos()	
	{
        //BGCamera.GetComponent<BlurEffect>().enabled = true;
        var blur_effect = Popup_Blur.Activate(UICamera);
        Popup_Blur.AddBackground(blur_effect, BGCamera);
		int i=1;
		if( UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList.Length > 0 )
		{
			foreach(int dispatchMemberId in UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList)
			{
				foreach( KeyValuePair<string, MemberModel> pair in UserData.Instance.userModel.members_dic)
				{
					if( dispatchMemberId == pair.Value.no )
					{
						if( i > memberCellList.Count )
						{
							GameObject obj = Resources.Load("Prefab/UI/memberList_select") as GameObject;
							GameObject memberCell = Instantiate(obj) as GameObject;
							memberCell.name = obj.name+i;
							memberCell.transform.parent = selectDispatchMemberListObject.transform;
							memberCell.transform.localScale = Vector3.one;
							memberCell.transform.localPosition = Vector3.zero;
							memberCell.GetComponent<LTButtonMessage>().enabled = true;
							memberCell.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventListener = this;
							memberCell.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventId = 1000+i;
							memberCellList.Add(memberCell.GetComponent<MemberListCell>());
						}

						if( !memberCellList[i-1].gameObject.activeSelf )
							memberCellList[i-1].gameObject.SetActive(true);

                        //memberCellList[i-1].memberImage.spriteName = GameData.Inst.ModelDefineDic[pair.Value.model];
                        foreach (UISprite sprite in memberCellList[i - 1].memberImage)
                            PortraitControl.SetPortrait(sprite, pair.Value);
                        foreach (UILabel label in memberCellList[i - 1].memberName)
							label.text = TextController.GetStringWithId(string.Format("charName{0}", pair.Value.name));
                        foreach (UILabel label in memberCellList[i - 1].memberLevel)
							label.text = string.Format("LV{0}", pair.Value.level);
                        foreach (UILabel label in memberCellList[i - 1].memberPoweLevel)
							label.text = string.Format("+{0}", pair.Value.strengthening);
                        //memberCellList[i-1].memberExpBar.value = (pair.Value.exp / (float)GameData.Inst.character[pair.Value.level-1].charExp);
                        float orizinx = 201.0f;

                        memberCellList[i - 1].memberExpBar.SetDimensions((int)(pair.Value.ExpPercent() * orizinx), 11);
                        foreach (GameObject obj in memberCellList[i - 1].rareBGOn)
                            obj.SetActive(false);
                        foreach (GameObject obj in memberCellList[i - 1].rareBGOff)
                            obj.SetActive(false);
                        memberCellList[i - 1].rareBGOn[pair.Value.rarity - 1].SetActive(true);
                        memberCellList[i - 1].rareBGOff[pair.Value.rarity - 1].SetActive(true);

						memberCellList[i-1].memberId = pair.Value.no;
						memberCellList[i-1].GetComponent<LTButtonMessage>().enabled = false;
						memberCellList[i-1].selectBox[0].SetActive(false);
						memberCellList[i-1].selectBox[1].SetActive(false);
                        memberCellList[i - 1].onOffObject[0].SetActive(true);
                        memberCellList[i - 1].onOffObject[1].SetActive(false);

						i++;
						break;
					}
				}
			}

			for(int j=i-1; j<memberCellList.Count; j++)
			{
				 memberCellList[j].gameObject.SetActive(false);
			}

			dispatchMemberMaxCountInDetail[1].text = string.Format("/ {0}", TextController.GetStringWithId("uiCommonTextMaxCount").Replace("{0}", GameData.Inst.regionLevel[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].dispatchNum.ToString()));
			dispatchMemberCountInDetail[1].text = TextController.GetStringWithId("uiCommonTextpeople").Replace("{0}", UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList.Length.ToString());
//			dispatchTimeInDetail[1].text = string.Format("{0:00}:{1:00}", (int)UserData.Instance.userModel.regions.regionMap[selectedAreaId].rem;
			
			dispatchButtonsInDetail[0].SetActive(false);
			dispatchButtonsInDetail[1].SetActive(true);
			dispatchDetailState[0].SetActive(false);
			dispatchDetailState[1].SetActive(true);
		}
		else
		{
			foreach( KeyValuePair<string, MemberModel> pair in UserData.Instance.userModel.members_dic)
			{
				if( !UserData.Instance.userModel.regions.isDispatchingMember(pair.Value.no) )
				{
					if( i > memberCellList.Count )
					{
						GameObject obj = Resources.Load("Prefab/UI/memberList_select") as GameObject;
						GameObject memberCell = Instantiate(obj) as GameObject;
						memberCell.name = obj.name+i;
						memberCell.transform.parent = selectDispatchMemberListObject.transform;
						memberCell.transform.localScale = Vector3.one;
						memberCell.transform.localPosition = Vector3.zero;
						memberCell.GetComponent<LTButtonMessage>().enabled = true;
						memberCell.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventListener = this;
						memberCell.GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventId = 1000+i;
						memberCellList.Add(memberCell.GetComponent<MemberListCell>());
					}

					if( !memberCellList[i-1].gameObject.activeSelf )
						memberCellList[i-1].gameObject.SetActive(true);

                    //memberCellList[i-1].memberImage.spriteName = GameData.Inst.ModelDefineDic[pair.Value.model];
                    foreach (UISprite sprite in memberCellList[i - 1].memberImage)
                        PortraitControl.SetPortrait(sprite, pair.Value);
                    foreach (UILabel label in memberCellList[i - 1].memberName)
                        label.text = TextController.GetStringWithId(string.Format("charName{0}", pair.Value.name));
                    foreach (UILabel label in memberCellList[i - 1].memberLevel)
                        label.text = string.Format("LV{0}", pair.Value.level);
                    foreach (UILabel label in memberCellList[i - 1].memberPoweLevel)
                        label.text = string.Format("+{0}", pair.Value.strengthening);
                    //memberCellList[i - 1].memberExpBar.value = (pair.Value.exp / (float)GameData.Inst.character[pair.Value.level - 1].charExp);
                    float orizinx = 201.0f;

                    memberCellList[i - 1].memberExpBar.SetDimensions((int)(pair.Value.ExpPercent() * orizinx), 11);
                    foreach (GameObject obj in memberCellList[i - 1].rareBGOn)
                        obj.SetActive(false);
                    foreach (GameObject obj in memberCellList[i - 1].rareBGOff)
                        obj.SetActive(false);
                    memberCellList[i - 1].rareBGOn[pair.Value.rarity - 1].SetActive(true);
                    memberCellList[i - 1].rareBGOff[pair.Value.rarity - 1].SetActive(true);

	//				for(int k=0; k<pair.Value.rarity; k++)
	//				{
	//					memberCellList[i-1].rareImageOn[k].gameObject.SetActive(true);
	//				}

                    //float startPosX = StarCenter - ((StarGap * (pair.Value.rarity - 1)) / 2);
					
                    //for (int k = 0; k < RareMax; k++)
                    //{
                    //    if (k < pair.Value.rarity)
                    //    {
                    //        Vector3 starPos = memberCellList[i-1].rareImageOn[k].transform.localPosition;
                    //        starPos.x = startPosX + (StarGap * k);
                    //        memberCellList[i-1].rareImageOn[k].transform.localPosition = starPos;
							
                    //        memberCellList[i-1].rareImageOn[k].gameObject.SetActive(true);
                    //    }
                    //    else
                    //    {
                    //        memberCellList[i-1].rareImageOn[k].gameObject.SetActive(false);
                    //    }
                    //}

					memberCellList[i-1].memberId = pair.Value.no;
					memberCellList[i-1].GetComponent<LTButtonMessage>().enabled = true;
					memberCellList[i-1].GetComponent<LTButtonMessage>().m_MethodDeliver[0].m_EventListener = this;
					memberCellList[i-1].selectBox[0].SetActive(false);
					memberCellList[i-1].selectBox[1].SetActive(true);
                    memberCellList[i - 1].onOffObject[0].SetActive(false);
                    memberCellList[i - 1].onOffObject[1].SetActive(true);
					
					i++;
				}
			}

			for(int j=i-1; j<memberCellList.Count; j++)
			{
				memberCellList[j].gameObject.SetActive(false);
			}

			dispatchMemberMaxCountInDetail[0].text = string.Format("/ {0}", TextController.GetStringWithId("uiCommonTextMaxCount").Replace("{0}", GameData.Inst.regionLevel[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].dispatchNum.ToString()));
			dispatchMemberCountInDetail[0].text = TextController.GetStringWithId("uiCommonTextpeople").Replace("{0}", "0");
			dispatchTimeInDetail[0].text = "00:00";

			dispatchButtonsInDetail[0].SetActive(true);
			dispatchButtonsInDetail[1].SetActive(false);
			dispatchDetailState[0].SetActive(true);
			dispatchDetailState[1].SetActive(false);

		}
		dispatchButton.SetActive(false);
		researchButton.SetActive(false);
		areaPointObjectList[selectedAreaIndex].SetActive(false);
		dispatchInfoViewObject.SetActive(true);
		selectDispatchMemberListObject.transform.parent.gameObject.GetComponent<UIScrollView>().contentPivot = UIWidget.Pivot.Top;
		selectDispatchMemberListObject.transform.parent.gameObject.GetComponent<UIScrollView>().ResetPosition();
	}
	
	List<int> selectedDispatchMemberList = new List<int>();
	void SelectDispatchMember(int index)
	{
		if( !selectedDispatchMemberList.Contains(memberCellList[index-1].memberId) )
		{
			if( selectedDispatchMemberList.Count < GameData.Inst.regionLevel[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].dispatchNum )
			{
				selectedDispatchMemberList.Add(memberCellList[index-1].memberId);
				memberCellList[index-1].selectBox[0].SetActive(true);
				memberCellList[index-1].selectBox[1].SetActive(false);
                memberCellList[index - 1].GetComponent<Animation>().Play();
                for(int k=index; k<memberCellList.Count; k++)
                {
                    Vector3 pos = memberCellList[k].transform.localPosition;
                    pos.y -= 20f;
                    memberCellList[k].transform.localPosition = pos;
                }
			}
			else
			{
				Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
				po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId("uiPopupWorldCaution7"));
			}
		}
		else
		{
			selectedDispatchMemberList.Remove(memberCellList[index-1].memberId);
			memberCellList[index-1].selectBox[0].SetActive(false);
			memberCellList[index-1].selectBox[1].SetActive(true);
            memberCellList[index - 1].onOffObject[0].SetActive(false);
            memberCellList[index - 1].onOffObject[1].SetActive(true);
            for (int k = index; k < memberCellList.Count; k++)
            {
                Vector3 pos = memberCellList[k].transform.localPosition;
                pos.y += 20f;
                memberCellList[k].transform.localPosition = pos;
            }
		}

		dispatchMemberCountInDetail[0].text = TextController.GetStringWithId("uiCommonTextpeople").Replace("{0}", selectedDispatchMemberList.Count.ToString());
		if( selectedDispatchMemberList.Count > 0 )
		{
			float dispatchTime = GameData.Inst.GetRegionData(int.Parse(selectedAreaId)).dispatchTime*GameData.Inst.dispatch[selectedDispatchMemberList.Count-1].timeMultiplier;
			Debug.LogError(GameData.Inst.region[UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionLevel-1].dispatchTime);
			dispatchTimeInDetail[0].text = string.Format("{0:00}:{1:00}", (int)dispatchTime/60, (int)dispatchTime%60);
		}
		else
			dispatchTimeInDetail[0].text = "00:00";

	}

	//0 : Heaven
	//1 : Hell
	static int selectedMainAreaIndex = 0;
	public void SelectMainAreaToHeaven()
	{
		selectedMainAreaIndex = 0;

	}

	public void SelectMainAreaToHell()
	{
		selectedMainAreaIndex = 1;
	}

	public void SetWorldMapInfo()
	{
		if( selectedMainAreaIndex == 0 )
		{
		}
		else
		{
		}
	}

	public void OnClickSendToResearch()
	{
		StandbyScene.startMode = BattleStartMode.Research;
        SceneController.LoadLevel("Lobby_4vs4");
//		int[] memberList = new int[4]{1,2,3,4};
//		NetworkManager.Instance.C2S_SEND_TO_RESEARCH(ResponseResearch, int.Parse(selectedAreaId), memberList);
	}

	private void ResponseResearch(ResponseModel<ResearchStartModel> result)
	{
		int[] seqNo = new int[2]{0,1};
		int[] seqType = new int[2]{1,2};
		NetworkManager.Instance.C2S_SEND_TO_RESEARCH_RESULT(ResponseResearchResult, int.Parse(selectedAreaId), 1, seqNo, seqType);
	}

	private void ResponseResearchResult(ResponseModel<ResearchResultModel> result)
	{
		//임시로 모든 전투가 승리한다고 가정한 상태
		UserData.Instance.userModel.exp += result.data.legionExp;
		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].regionExp += result.data.regionExp;
		UserData.Instance.userModel.kina += result.data.kina;
		for(int i=0; i<result.data.memberExp.Length; i++)
		{
			UserData.Instance.userModel.members_dic[result.data.memberExp[i][0].ToString()].exp += result.data.memberExp[i][1];
		}
		if( UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen < GameData.Inst.GetMaxResourceSpotCount(int.Parse(selectedAreaId)) )
		{
			UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen += 1;
			Transform areaObject = areaPointObjectList[selectedAreaIndex].transform.FindChild("area_0"+UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].spotOpen);
			areaObject.FindChild("01").gameObject.SetActive(false);
			areaObject.FindChild("02").gameObject.SetActive(true);
			areaObject.FindChild("02").FindChild("new").gameObject.SetActive(true);
		}
		SetAreaInfo();
	}

	public void OnClickSendToDispatch()
	{
		if( UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList.Length == 0 )
		{
			if( selectedDispatchMemberList.Count != 0 )
			{
				int[] memberList = selectedDispatchMemberList.ToArray();
				NetworkManager.Instance.C2S_SEND_TO_DISPATCH(ResponseSendDispatch, int.Parse(selectedAreaId), memberList);
			}
			else
			{
				Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
				po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId("uiPopupWorldCaution6"));
			}
		}
		else
		{
			Popup_TwoButton pt = PopupManager.PushPopup(PopupKind.TwoButton) as Popup_TwoButton;
			pt.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId("uiPopupWorldCaution1"));
			pt.SetPopupWithYesNoString(TextController.GetStringWithId("uiWorldDispatchCancel"), TextController.GetStringWithId("uiCommonTextCancel"));
			pt.SetEventOK(gameObject, "OnClickCancelDispatch");
		}
	}

	public void OnClickCancelDispatch()
	{
		NetworkManager.Instance.C2S_CANCEL_DISPTCH(ResponseCancelDispatch, int.Parse(selectedAreaId));
	}

	public void OnClickCloseDispatchInfoWindow()
	{
		foreach(MemberListCell cell in memberCellList)
		{
			cell.selectBox[0].SetActive(true);
			cell.selectBox[1].SetActive(true);
		}
		selectedDispatchMemberList.Clear();
		selectedMemberIndex = -1;
		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
		areaPointObjectList[selectedAreaIndex].SetActive(true);
		dispatchInfoViewObject.SetActive(false);
		Popup_Blur.ClearAll();
        //BGCamera.GetComponent<BlurEffect>().enabled = false;
        var blur_effect = Popup_Blur.GetActivated(UICamera);
        Popup_Blur.RemoveBackground(blur_effect, BGCamera);
        Popup_Blur.Deactivate(UICamera);
	}

	public void OnClickDispatchButton()
	{
		Debug.LogError(UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].endDispatch);
		DateTime disPatchEndTime = Constants.ConvertFromUnixTimestamp(UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].endDispatch);
		Debug.LogError(disPatchEndTime.ToString());
		Debug.LogError(DateTime.Now);
		TimeSpan timeGap = disPatchEndTime - (DateTime.Now - UserData.Instance.serverTimeOffsetSpan);
		Debug.LogError(timeGap.Seconds);
		Debug.LogError(timeGap.TotalSeconds);
		              
//		if( UserData.Instance.userModel.regions.regionMap[selectedAreaId].dispatchMList.Length == 0 )
//		{
//			int[] memberList = new int[1]{1};
//			NetworkManager.Instance.C2S_SEND_TO_DISPATCH(ResponseSendDispatch, int.Parse(selectedAreaId), memberList);
//		}
		if( UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList.Length > 0 && timeGap.TotalSeconds <= 0)
		{
			NetworkManager.Instance.C2S_COMPLETE_DISPTCH(ResponseCompleteDispatch, int.Parse(selectedAreaId));
		}
		else
		{
			SetDispathInfoViewInfos();
		}
	}

	private void ResponseSendDispatch(ResponseModel<Region> result)
	{
		if( result.ecode != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(result.ecode))));
			return;
		}

        if (result.responseResult.completeIdList.Count != 0)
        {
            foreach (int id in result.responseResult.completeIdList)
            {
                ToastManager.Instance.ShowAchievementCompleteToast(id, true);
            }
        }

        Invoke("GetQuestInfo", 0.5f);

		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId] = result.data;
		selectedDispatchMemberList.Clear();
		selectedMemberIndex = -1;
		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
		areaPointObjectList[selectedAreaIndex].SetActive(true);
		dispatchInfoViewObject.SetActive(false);
		dispatchNormalButton.SetActive(false);
		dispatchIngButton.SetActive(true);
		dispatchEndButton.SetActive(false);
		Popup_Blur.ClearAll();

        var blur_effect = Popup_Blur.GetActivated(UICamera);
        Popup_Blur.RemoveBackground(blur_effect, BGCamera);
        Popup_Blur.Deactivate(UICamera);
        //BGCamera.GetComponent<BlurEffect>().enabled = false;
		
		SetAreaInfo();
		SetWorldMapInfos();
	}

	private void ResponseGetLegionInfo(ResponseModel<UserModel> result)
	{
		if( result.ecode != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(result.ecode))));
			return;
		}

		selectedDispatchMemberList.Clear();
		UserData.Instance.userModel = result.data;
		selectedMemberIndex = -1;
		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
		areaPointObjectList[selectedAreaIndex].SetActive(true);
		dispatchInfoViewObject.SetActive(false);
		dispatchNormalButton.SetActive(false);
		dispatchIngButton.SetActive(true);
		dispatchEndButton.SetActive(false);
		Popup_Blur.ClearAll();
		
		SetAreaInfo();
		SetWorldMapInfos();
	}

	private void ResponseGetDispatchInfo(ResponseModel<Region> result)
	{
		if( result.ecode != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(result.ecode))));
			return;
		}

		selectedDispatchMemberList.Clear();
 		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId] = result.data;
		selectedMemberIndex = -1;
		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
		areaPointObjectList[selectedAreaIndex].SetActive(true);
		dispatchInfoViewObject.SetActive(false);
		dispatchNormalButton.SetActive(false);
		dispatchIngButton.SetActive(true);
		dispatchEndButton.SetActive(false);
		Popup_Blur.ClearAll();
		
		SetAreaInfo();
		SetWorldMapInfos();
	}

	private void ResponseCancelDispatch(ResponseModel<DispatchCompleteResultModel> result)
	{
		if( result.ecode != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(result.ecode))));
			return;
		}

		UserData.Instance.userModel.kina += result.data.kina;
		Popup_DispatchCancelReward rewardPopup = PopupManager.PushPopup(PopupKind.DispatchCancelReward) as Popup_DispatchCancelReward;
		rewardPopup.SetDispatchMemberInfos(result.data.memberExp);

		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].dispatchMList = new int[0];
		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].endDispatch = 0;
		UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId].remainDispatchTime = 0;

		selectedDispatchMemberList.Clear();
		selectedMemberIndex = -1;
		dispatchButton.SetActive(true);
		researchButton.SetActive(true);
		areaPointObjectList[selectedAreaIndex].SetActive(true);
		dispatchInfoViewObject.SetActive(false);
		dispatchNormalButton.SetActive(false);
		dispatchIngButton.SetActive(true);
		dispatchEndButton.SetActive(false);
		Popup_Blur.ClearAll();

        var blur_effect = Popup_Blur.GetActivated(UICamera);
        Popup_Blur.RemoveBackground(blur_effect, BGCamera);
        Popup_Blur.Deactivate(UICamera);
        //BGCamera.GetComponent<BlurEffect>().enabled = false;
		
		SetAreaInfo();
		SetWorldMapInfos();

//		NetworkManager.Instance.C2S_GET_DISPATCH_INFO(ResponseGetDispatchInfo, int.Parse(selectedAreaId), selectedDispatchMemberList.ToArray());
	}

	private void ResponseCompleteDispatch(ResponseModel<DispatchCompleteResultModel> result)
	{
//		UserData.Instance.userModel.exp += result.data.legionExp;

//		for(int i=0; i<result.data.memberExp.Length; i++)
//		{
//			UserData.Instance.userModel.members[result.data.memberExp[i][0].ToString()].exp += result.data.memberExp[i][1];
//		}

		if( result.ecode != 0 )
		{
			Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
			po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(result.ecode))));
			return;
		}

        if (result.responseResult.completeIdList.Count != 0)
        {
            foreach (int id in result.responseResult.completeIdList)
            {
                ToastManager.Instance.ShowAchievementCompleteToast(id, true);
            }
        }

		Popup_DispatchReward rewardPopup = PopupManager.PushPopup(PopupKind.DispatchReward) as Popup_DispatchReward;
		rewardPopup.SetLegionInfos(result.data.legionExp);
		rewardPopup.SetItemInfos(result.data.item, result.data.member);
		rewardPopup.SetDispatchMemberInfos(result.data.memberExp);

		ToastUtility.LevelUpToast();

        Invoke("GetQuestInfo", 0.5f);

		NetworkManager.Instance.C2S_LEGION_GET(ResponseGetLegionInfo);
	}

	void CheckAndShowDispatchRemainTime()
	{
		if( !areaViewObject.activeSelf )
		{
			foreach(KeyValuePair<string, Region> pair in UserData.Instance.userModel.regions.regionMap_Dic)
			{
				if( pair.Value.dispatchMList.Length > 0 && pair.Value.remainDispatchTime > 0 )
				{
					TimeSpan remainTime = Constants.ConvertFromUnixTimestamp(pair.Value.endDispatch) - (DateTime.Now  - UserData.Instance.serverTimeOffsetSpan);
					if( remainTime.TotalSeconds > 0 )
					{
						if( areaDispatchRemainTimeInWorldMap[pair.Value.id - 100] != null )
						{
		//					    staminaNextTickTime.gameObject.SetActive(true);
							areaDispatchRemainTimeInWorldMap[pair.Value.id - 100].text = string.Format("{0:00}:{1:00}", (int)remainTime.TotalSeconds/60, (int)remainTime.TotalSeconds%60); 
							areaDispatchMemberCountInWorldMap[pair.Value.id - 100].text = TextController.GetStringWithId("uiCommonTextpeople").Replace("{0}", pair.Value.dispatchMList.Length.ToString());
							areaDispatchIngMarkObject[pair.Value.id-100].SetActive(true);
						}
					}
					else
					{
						areaDispatchIngMarkObject[pair.Value.id-100].SetActive(false);
						areaNoDispatchMarkObject[pair.Value.id-100].SetActive(true);
					}
				}
				else
				{
					//staminaNextTickTime.gameObject.SetActive(false);
				}
			}
		}
		else
		{
			Region regionInfo = UserData.Instance.userModel.regions.regionMap_Dic[selectedAreaId];
			TimeSpan remainTime = Constants.ConvertFromUnixTimestamp(regionInfo.endDispatch) - (DateTime.Now - UserData.Instance.serverTimeOffsetSpan);
			if( regionInfo.dispatchMList.Length > 0 && remainTime.TotalSeconds <= 0 )
			{
				dispatchButton.SetActive(true);
				researchButton.SetActive(true);
				areaPointObjectList[selectedAreaIndex].SetActive(true);
				dispatchInfoViewObject.SetActive(false);
				dispatchNormalButton.SetActive(false);
				dispatchIngButton.SetActive(false);
				dispatchEndButton.SetActive(true);

				Popup_Blur.ClearAll();
			}
			else if( dispatchInfoViewObject.activeSelf && regionInfo.dispatchMList.Length > 0 && remainTime.TotalSeconds > 0 )
			{
				dispatchTimeInDetail[1].text = string.Format("{0:00}:{1:00}", (int)remainTime.TotalSeconds/60, (int)remainTime.TotalSeconds%60);
			}
		}
	}

    void GetQuestInfo()
    {
        NetworkManager.Instance.C2S_GET_QUESTINFO(QuestManager.instance.ResponseGetQuestInfo);
    }
}
